<?php
        require_once("koneksi.php");
        $query1 = mysql_query ("SELECT SUM(kunjungan_iklan) AS kunjunganiklan FROM kunjungandetiliklan");
        $kunjunganiklan = mysql_fetch_array($query1);

        $query2 = mysql_query ("SELECT COUNT(email) AS banyakanggota FROM anggota");
        $banyakanggota = mysql_fetch_array($query2);

        $query3 = mysql_query ("SELECT SUM(harga) AS totalharga, COUNT(id_iklan) AS banyakiklan FROM iklan");
        $iklan = mysql_fetch_array($query3);

        $query4 = mysql_query("SELECT * FROM kunjungan WHERE tgl_kunjungan = curdate()");
        $kunjungansekarang = mysql_fetch_array($query4);

        $query5 = mysql_query("SELECT *, SUM(kunjungan_iklan) as banyak_detil FROM iklan NATURAL JOIN kunjungandetiliklan group by judul_iklan desc limit 5");

        $query6 = mysql_query("SELECT * FROM anggota NATURAL JOIN iklan NATURAl JOIN kunjungandetiliklan order by COUNT(id_iklan) desc limit 5");

?>    

    <div id='wrap'>
        <div id="page-heading"> 
            <ol class="breadcrumb">
                <li class='active'><a href="index.php">Dashboad</a></li>
            </ol>

            <h1>Dashboard</h1>
            
            <div class="options">
                    <a href="index.php?page=2" class="btn btn-muted hidden-xs"><i class="icon-cog"></i></a>
                
            </div>
        </div>


        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <div class="row">
                        <div class="col-md-3 col-xs-12 col-sm-6">
                            <a class="info-tiles tiles-brown" href="#">
                                <div class="tiles-heading">Banyak Kunjungan Hari Ini</div>
                                <div class="tiles-body-alt">
                                    <div class="text-center"><?php echo $kunjungansekarang['banyak_kunjungan']; ?></div>
                                </div>
                                <div class="tiles-footer">more info</div>
                            </a>
                        </div>
                        <div class="col-md-3 col-xs-12 col-sm-6">
                            <a class="info-tiles tiles-grape" href="#">
                                <div class="tiles-heading">Total Harga Seluruh Iklan</div>
                                <div class="tiles-body-alt">
                                    <div class="text-center"><span class="text-top"><font size="3">Rp. <?php echo $iklan['totalharga']; ?></font></div>
                                </div>
                                <div class="tiles-footer">lihat tabel</div>
                            </a>
                        </div>
                        <div class="col-md-3 col-xs-12 col-sm-6">
                            <a class="info-tiles tiles-success" href="#">
                                <div class="tiles-heading">Banyak Anggota</div>
                                <div class="tiles-body-alt">
                                    <i class="icon-group"></i>
                                    <div class="text-center"><?php echo $banyakanggota['banyakanggota']; ?></div>
                                </div>
                                <div class="tiles-footer">manage anggota</div>
                            </a>
                        </div>
                        <div class="col-md-3 col-xs-12 col-sm-6">
                            <a class="info-tiles tiles-midnightblue" href="#">
                                <div class="tiles-heading">Banayk Iklan</div>
                                <div class="tiles-body-alt">
                                    <i class="icon-shopping-cart"></i>
                                    <div class="text-center"><?php echo $iklan['banyakiklan']; ?></div>
                                </div>
                                <div class="tiles-footer">manage iklan</div>
                            </a>
                        </div>
                    </div>
                </div>
            </div>

<div class="row">
                <div class="col-md-6">
                    <div class="panel gray">
                        <div class="panel-heading">
                              <h4>Iklan yang Paling Banyak Dilihat</h4>
                              <div class="options">
                                <a href="javascript:;"><i class="icon-cog"></i></a>
                                <a href="javascript:;"><i class="icon-wrench"></i></a> 
                                <a href="javascript:;" class="panel-collapse"><i class="icon-chevron-down"></i></a>
                              </div>
                        </div>
                        <div class="panel-body collapse in">
                            <div class="table-responsive" style="overflow-x:auto">
                                <table class="table">
                                    <thead>
                                        <tr>
                                            <th width="6%"><input type="checkbox" id="select-all" /></th>
                                            <th width="22%">Judul Iklan</th>
                                            <th width="50%">Email</th>
                                            <th width="22%">Banyak Kunjungan</th>
                                        </tr>
                                    </thead>
                                    <tbody class="selects">
                                        <?php while ($ib = mysql_fetch_assoc($query5)) { ?>
                                        <tr>
                                            <td><input type="checkbox" class="" /></td>
                                            <td><?php echo $ib['judul_iklan']; ?></td>
                                            <td><?php echo $ib['email']; ?></td>
                                            <td><span class="label label-success"><?php echo $ib['banyak_detil']; ?></span></td>
                                        </tr>
                                        <?php } ?>
                                    </tbody>
                                    <tfoot>
                                        <tr class="active">
                                        </tr>
                                    </tfoot>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="panel gray">
                        <div class="panel-heading">
                              <h4>Admin yang Iklannya Terbanyak</h4>
                              <div class="options">
                                <a href="javascript:;"><i class="icon-cog"></i></a>
                                <a href="javascript:;"><i class="icon-wrench"></i></a> 
                                <a href="javascript:;" class="panel-collapse"><i class="icon-chevron-down"></i></a>
                              </div>
                        </div>
                        <div class="panel-body collapse in">
                            <div class="table-responsive" style="overflow-x:auto">
                                <table class="table">
                                    <thead>
                                        <tr>
                                            <th width="6%"><input type="checkbox" id="select-all" /></th>
                                            <th width="22%">username</th>
                                            <th width="50%">Email</th>
                                            <th width="22%">Banyak iklan</th>
                                        </tr>
                                    </thead>
                                    <tbody class="selects">
                                        <?php while ($ib1 = mysql_fetch_assoc($query6)) { ?>
                                        <?php 
                                        $email1 = $ib1['email'];
                                        $qib = mysql_query("SELECT count(id_iklan) AS banyak FROM iklan NATURAL JOIN anggota WHERE email = '$email1'");
                                        $qib1 = mysql_fetch_array($qib);
                                        ?>
                                        <tr>
                                            <td><input type="checkbox" class="" /></td>
                                            <td><?php echo $ib1['username']; ?></td>
                                            <td><?php echo $ib1['email']; ?></td>
                                            <td><span class="label label-success"><?php echo $qib1['banyak']; ?></span></td>
                                        </tr>
                                        <?php } ?>
                                    </tbody>
                                    <tfoot>
                                        <tr class="active">
                                        </tr>
                                    </tfoot>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            

        </div> <!-- container -->
    </div> <!--wrap -->
